package com.skivingcloud.report.service.impl;

import com.mybatisflex.spring.service.impl.ServiceImpl;
import com.skivingcloud.report.entity.ReportExcel;
import com.skivingcloud.report.mapper.ReportExcelMapper;
import com.skivingcloud.report.service.ReportExcelService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import com.mybatisflex.core.paginate.Page;
import com.mybatisflex.core.query.QueryWrapper;
import com.skivingcloud.common.utils.PageParameter;

/**
 * excel报表 服务层实现。
 *
 * @author skivingcloud
 * @since 2024-09-12
 */
@Service
public class ReportExcelServiceImpl extends ServiceImpl<ReportExcelMapper, ReportExcel> implements ReportExcelService {

    /**
     * 分页查询excel报表
     *
     * @param parameter 查询参数
     * @return 分页查询结果
     */
    @Override
    public Page<ReportExcel> queryByPage(PageParameter<ReportExcel> parameter){
        Page<ReportExcel> page = new Page<>(parameter.getPage(), parameter.getPageSize());
        QueryWrapper queryWrapper = QueryWrapper.create();
        if (parameter.getParam() != null) {
            //查询条件
            if (StringUtils.isNoneBlank(parameter.getParam().getId())) {
                queryWrapper.and(ReportExcel::getId).like(parameter.getParam().getId());
            }
            if (StringUtils.isNoneBlank(parameter.getParam().getReportCode())) {
                queryWrapper.and(ReportExcel::getReportCode).like(parameter.getParam().getReportCode());
            }
            if (StringUtils.isNoneBlank(parameter.getParam().getSetCodes())) {
                queryWrapper.and(ReportExcel::getSetCodes).like(parameter.getParam().getSetCodes());
            }
            if (StringUtils.isNoneBlank(parameter.getParam().getSetParam())) {
                queryWrapper.and(ReportExcel::getSetParam).like(parameter.getParam().getSetParam());
            }
            if (StringUtils.isNoneBlank(parameter.getParam().getJsonStr())) {
                queryWrapper.and(ReportExcel::getJsonStr).like(parameter.getParam().getJsonStr());
            }
            if (StringUtils.isNoneBlank(parameter.getParam().getEnableFlag())) {
                queryWrapper.and(ReportExcel::getEnableFlag).like(parameter.getParam().getEnableFlag());
            }
            if (StringUtils.isNoneBlank(parameter.getParam().getDeleteFlag())) {
                queryWrapper.and(ReportExcel::getDeleteFlag).like(parameter.getParam().getDeleteFlag());
            }
            if (StringUtils.isNoneBlank(parameter.getParam().getCreateBy())) {
                queryWrapper.and(ReportExcel::getCreateBy).like(parameter.getParam().getCreateBy());
            }
            if (StringUtils.isNoneBlank(parameter.getParam().getUpdateBy())) {
                queryWrapper.and(ReportExcel::getUpdateBy).like(parameter.getParam().getUpdateBy());
            }
        }
        return this.page(page, queryWrapper);
    }
}
